using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TuringMachine;

namespace SimulatorGui
{
    public partial class InputLoad : Form
    {
        private TapeControl _tapeControl = null;
        private Controller _controller = null;
        public InputLoad()
        {
            InitializeComponent();
        }
        public InputLoad(ref TapeControl tapeControl, ref Controller controller)
        {
            InitializeComponent();
            _tapeControl = tapeControl;
            _controller = controller;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UInt16 i;
            string input;
            try
            {
                
                i = UInt16.Parse(textBox2.Text);
                input = "#" + textBox1.Text;
                if (i<0)
                {
                    throw new FormatException();
                }
                _tapeControl.CurrentIndex = i;
                _tapeControl.Text = input;
                _controller.SetTapeIndex(i);
                _controller.SetTapeString(input);
                this.Close();
            }
            catch (FormatException e1)
            {

                MessageBox.Show(e1.Message+Environment.NewLine+"Index should be non-negative number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
           
        }
    }
}